//
//  TabbarViewController.m
//  DS_PJ_01
//
//  Created by 宋畅 on 2016/12/15.
//  Copyright © 2016年 zhiqiyun. All rights reserved.
//

#import "TabbarViewController.h"
#import "QueueViewController.h"
#import "EatOutViewController.h"
#import "GatherViewController.h"
#import "MineViewController.h"
#import "HornViewController.h"
#import "RDVTabBarItem.h"
#import "UIImageView+Normal.h"
@interface TabbarViewController ()<RDVTabBarControllerDelegate>

@property(nonatomic,strong)QueueViewController *queueVC;

@property(nonatomic,strong)EatOutViewController *eatOutVC;

@property(nonatomic,strong)GatherViewController *gatherVC;

@property(nonatomic,strong)MineViewController *mineVC;

@property (nonatomic,strong)ViewController *hornVC;
@property (nonatomic,assign)NSInteger selectIndex;
@end

@implementation TabbarViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        [self setUp];
    }
    return self;
}

-(void)setUp
{
    self.queueVC=[[QueueViewController alloc]init];
    self.eatOutVC=[[EatOutViewController alloc]init];
    self.gatherVC=[[GatherViewController alloc]init];
    self.mineVC=[[MineViewController alloc]init];
    self.hornVC=[[HornViewController alloc]init];
    
    self.hidesBottomBarWhenPushed=NO;

    UINavigationController *queueNAV=[[UINavigationController alloc]initWithRootViewController:self.queueVC];
    queueNAV.title=@"排队";
    UINavigationController *eatOutNAV=[[UINavigationController alloc]initWithRootViewController:self.eatOutVC];
    queueNAV.title=@"餐台";
    UINavigationController *hornNAv=[[UINavigationController alloc]initWithRootViewController:self.hornVC];

    UINavigationController *gatherNAV=[[UINavigationController alloc]initWithRootViewController:self.gatherVC];
    queueNAV.title=@"系统";
    UINavigationController *mineNAV=[[UINavigationController alloc]initWithRootViewController:self.mineVC];
    queueNAV.title=@"我的";
    self.viewControllers=[NSArray arrayWithObjects:queueNAV,eatOutNAV,hornNAv,gatherNAV,mineNAV, nil];
    self.navigationController.navigationBarHidden = YES;
    [self customizeFlatStyleTabbar];
    self.tabBar.backgroundView.backgroundColor=[UIColor blackColor];
    self.delegate=self;

}
-(void)customizeFlatStyleTabbar
{
    int i = 0;
    NSArray *itemNames=[NSArray arrayWithObjects:@"排队",@"餐台",@"1",@"系统",@"我的", nil];
    for (RDVTabBarItem *item in self.tabBar.items) {
        if ([itemNames[i] isEqualToString:@"1"]) {
            UIImage *lapaImage = [UIImageView addImage:@"anniuhei" withImage:@"lapa"];
            [item setFinishedSelectedImage:lapaImage withFinishedUnselectedImage:lapaImage];
            item.itemHeight = 80;
        }
        else{
        [item setTitle:itemNames[i]];
            item.selectedTitleAttributes= @{
                                            NSFontAttributeName: [UIFont boldSystemFontOfSize:20],
                                            NSForegroundColorAttributeName:[UIColor colorWithRed:0.27f green:0.66f blue:0.42f alpha:1.00f],
                                            };
            item.unselectedTitleAttributes = @{
                                               NSFontAttributeName: [UIFont boldSystemFontOfSize:20],
                                               NSForegroundColorAttributeName:[UIColor whiteColor],
                                               };
        }
        i++;

    }
}


- (BOOL)tabBarController:(RDVTabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    self.selectIndex=tabBarController.selectedIndex;
    return YES;
}

- (void)tabBarController:(RDVTabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    if (tabBarController.selectedIndex==2) {
        tabBarController.selectedIndex=self.selectIndex;
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
   
    DSLog(@"111");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
